package leetcode;

import java.util.Arrays;

/**
 * 对数组进行去重,只能使用数组
 *
 * @auther 王霄
 * @date 2022/8/12 09:02
 */
public class Code003 {
    public static void main(String[] args) {
        int[] arr = {1, 4, 2, 5, 7, 3, 3, 5, 1, 0, 8};
        System.out.println(Arrays.toString(test(arr)));
    }

    private static int[] test(int[] arr) {
        int[] brr = new int[arr.length];
        int index = 0;
        for (int k : arr) {
            boolean flag = true;
            for (int j = 0; j < index; j++) {
                if (k == brr[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                brr[index] = k;
                index++;
            }
        }
        return Arrays.copyOfRange(brr, 0, index);
    }

}
